package edu.zju.gis.dbfg.common.util;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FileOperation {

    public static boolean exist(String path) {
        return Files.exists(Paths.get(path));
    }

    public static void deletePath(String path) throws IOException {
        deletePath(new File(path));
    }

    public static void deletePath(File path) throws IOException {
        if (path.exists()) {
            if (path.isFile())
                Files.delete(path.toPath());
            else {
                File[] subPaths = path.listFiles();
                if (subPaths != null)
                    for (File subPath : subPaths)
                        deletePath(subPath);
                Files.delete(path.toPath());
            }
        }
    }

}
